import qs from 'qs';
import fetch from '@/utils/fetch';

// 上传歌曲
// Song {
//   id, name, creator, description, price, soldAmount, authAmount,
//   authFilePath, musicHash, musicFilePath, autograph, play
// }
export function uploadSong(data) {
  const { songFilePath, ...others } = data;
  return fetch({
    url: `/song/upload?songfilepath=${songFilePath}`,
    method: 'post',
    data: others,
  });
}

// 获取歌曲
// GET /song/download?id=

// 上传歌曲文件
// POST /upload/singleFile

// 购买歌曲
// ?uid=&sid=
export function buySong(data) {
  return fetch({
    url: `/song/buy?${qs.stringify(data)}`,
    method: 'post',
  });
}

// 查询指定歌手的歌曲
export function querySingerSongs(sid) {
  return fetch({
    url: `/song/my_upload_songs?sid=${sid}`,
    method: 'get',
  });
}

// 查询所有歌曲
export function queryAllSongs() {
  return fetch({
    url: '/song/all_songs',
    method: 'get',
  });
}

// 查询歌曲详情
export function querySong(sid) {
  return fetch({
    url: `/song/getOne?sid=${sid}`,
    method: 'get',
  });
}
